<template>
    <div class="form-content form-vertical">
        <div class="form">
            <h1 class="logo-title">ChatChat</h1>
            <div class="input-item">
                <input class="" type="text" name="userName" v-model="userName" placeholder="请输入用户名">
            </div>
            <div class="input-item">
                <input class="" type="password" name="password" v-model="password" placeholder="请输入密码">
            </div>
            <div class="input-link-content">
                <router-link to="/forgetPsd">忘记密码？</router-link>
                <router-link to="/register">没有账号？</router-link>
            </div>
            <button class="pr-btn pr-btn-block" type="submit" @click.prevent="login">登 陆</button>
        </div>
    </div>
</template>

<script>
    import Vue from 'vue';
    import Mint from 'mint-ui';

    Vue.use(Mint);

    export default {
        data() {
            return {
                userName : '1',
                password : '1'
            }
        },
        components : {
        },
        methods: {
            login() {
                if(this.userName <= 0) {
                    Mint.Toast({
                        message: '请输入用户名',
                        duration: 1250
                    })
                    return false
                }

                if(this.password <= 0) {
                    Mint.Toast({
                        message: '请输入密码',
                        duration: 1250
                    })
                    return false
                }

                var data = {
                    userName : this.userName,
                    psd : this.password
                }
                
                this.$http({
                    method : 'post',
                    url : 'http://localhost:3000/api/login',
                    params : data
                }).then( res => {
                    Mint.Toast({
                        message: res.data.msg,
                        duration: 2000
                    })

                    sessionStorage.id = res.data.id;
                    sessionStorage.token = res.data.token;

                    if(res.data.status == 0) {
                        setTimeout( () => {
                            this.$rt.push('/Index');
                        }, 250)
                    }else {
                        
                    }
                })
            },
            checkData(test) {

            }
        }
    }
</script>